import { defineConfig } from "@rsbuild/core";
import { pluginVue } from "@rsbuild/plugin-vue";
import { pluginLess } from "@rsbuild/plugin-less";
import { pluginBabel } from "@rsbuild/plugin-babel";
import { pluginVueJsx } from "@rsbuild/plugin-vue-jsx";
import { RsdoctorRspackPlugin } from "@rsdoctor/rspack-plugin";

export default defineConfig({
  source: {
    entry: { index: "./src/index.ts" },
    alias: {
      "@": "./src",
    },
  },
  server: {
    htmlFallback: "index",
    port: 8888,
    open: false,
    host: "0.0.0.0",
  },
  html: {
    template: "./public/index.html",
  },
  plugins: [
    pluginBabel({
      include: /\.(?:jsx|tsx)$/,
    }),
    pluginVue(),
    pluginVueJsx(),
    pluginLess({
      lessLoaderOptions: {
        additionalData: `@import (reference) "/src/base.less";`,
        lessOptions: {
          javascriptEnabled: true,
        },
      },
    }),
  ],
  tools: {
    rspack: (config, { appendPlugins }) => {
      if (process.env.RSDOCTOR === "true") {
        appendPlugins(new RsdoctorRspackPlugin());
      }
    },
  },
});
